package cn.chrisx.drad.admob;

import android.content.Context;

import com.google.android.gms.ads.InterstitialAd;

/**
 * @author Jzfox <jz_boy@163.com>
 * @version 1.0
 * @date 2018/9/26 11:14
 * @description
 * @copyright ©2018 www.jzfox.net All rights reserved.
 */
public class InterstitialImpl extends BaseAd {

    private InterstitialAd interstitialAd;



    @Override
    public boolean loadAd(Context context) {
        super.loadAd(context);

        if (interstitialAd == null) {
            interstitialAd = new InterstitialAd(context);
            interstitialAd.setAdUnitId(drAdConfig.getAdUnitId());
            interstitialAd.setAdListener(googleAdListener);

            if (drAdConfig instanceof AdMobAdConfig) {
                interstitialAd.setImmersiveMode(((AdMobAdConfig) drAdConfig).isImmersiveMode());
            }

        }

        interstitialAd.loadAd(adRequest);

        return true;
    }

    @Override
    public boolean show() {
        if (isValid()) {
            interstitialAd.show();
            return true;
        }

        return false;

    }


    @Override
    public boolean isValid() {
        return interstitialAd != null && interstitialAd.isLoaded();
    }

}
